package org.reborn.engine.render.texture

import java.nio.Buffer
import javax.media.opengl.{GL,GL2GL3}

trait Tex2D extends Tex1D{
  self: TextureMetadata =>
  var height:Int = 0
  override val glTarget:Int = GL.GL_TEXTURE_2D
  override val texDimensions:Int = 2
}

class Texture2DMetadata extends Tex2D with BaseTextureMetadata 

/**
 * Create a new OpenGL texture.
 * @param metadata The Texture2DMetadata associated with this texture
 */
class Texture2D(val metadata:Texture2DMetadata) extends Texture {

  protected def setImageData(gl: GL, images: Seq[Buffer], glFormat:Int, glType: Int): Unit = {
	var level = 0
	while(level < images.size){
	  val imgData = images(level)
	  imgData.rewind
	  
	  gl.glTexImage2D(
	 		  metadata.glTarget,			//Should be GL_TEXTURE_2D
	 		  level,						//The mip-map level of the texture
	 		  metadata.glInternalFormat,	//The format that OpenGL wil use to store the texture in video memory
	 		  metadata.width,				//Width of the image in pixels
	 		  metadata.height,				//Height of the image in pixels
	 		  0,							//Width of the border
	 		  glFormat,						//The OpenGL format if the data in the image buffer
	 		  glType,						//The OpenGL type of data in the image buffer
	 		  imgData)						//The buffer that holds the image data
	  level += 1
	}
  }

}